package com.chj.design.sk;

// https://blog.csdn.net/rocketeerLi/article/details/81562806
public class Code11_Decorator {
	public interface Person {
		public void talk();
	}

	public static class GoodPerson implements Person {
		public GoodPerson() {

		}

		@Override
		public void talk() {
			System.out.println("I am a good person");
		}
	}

	public static abstract class AbstractPerson implements Person {
		protected final Person person;

		public AbstractPerson(Person person) {
			this.person = person;
		}

		@Override
		public void talk() {
			person.talk();
		}
	}

	public static class Father extends AbstractPerson implements Person {
		public Father(Person person) {
			super(person);
		}

		@Override
		public void talk() {
			super.talk();
			talkOtherThing();
		}

		public void talkOtherThing() {
			System.out.println("I am a father");
		}
	}

	public static class Student extends AbstractPerson implements Person {
		public Student(Person person) {
			super(person);
		}

		@Override
		public void talk() {
			super.talk();
			talkOtherThing();
		}

		public void talkOtherThing() {
			System.out.println("I am a student");
		}
	}

	public static class Teacher extends AbstractPerson implements Person {
		public Teacher(Person person) {
			super(person);
		}

		@Override
		public void talk() {
			super.talk();
			talkOtherThing();
		}

		public void talkOtherThing() {
			System.out.println("I am a teacher");
		}
	}

	public static void main(String[] args) {
		Father father = new Father(new Teacher(new Student(new GoodPerson())));
		father.talk();
	}
}
